#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <string.h>
#include <assert.h>
#define NUM 1024
#define OPT_NUM 64

char lineCommand[NUM];
char *myargv[OPT_NUM];
int main()
{
    while(1)
    {
         //输入提示符
    printf("用户名@主机名 当前路径#");
    fflush(stdout);//刷新缓冲区
    char *s= fgets(lineCommand,sizeof(lineCommand)-1,stdin);
    assert(s != NULL);
    (void)s;
    //清楚最后一个\n
    lineCommand[strlen(lineCommand)-1]=0;
   // printf("test:%s\n",lineCommand);
    myargv[0]=strtok(lineCommand," ");//字符串切割，以空格切割
    int i=1;
    while(myargv[i++]= strtok(NULL," "));
#ifdef DEBUG
    for(i=0;myargv[i];i++)
    {
        printf("myargv[%d]:%s\n",i,myargv[i]);
    }
#endif
    //执行命令
    pid_t id=fork();
    assert(id != -1);
    if(id==0)
    {
        execvp(myargv[0],myargv);
            exit(1);
    }
    waitpid(id,NULL,0);
    }   
}
